<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>子访问父-parent-root</title>
</head>
<script src="../js/vue.js"></script>
<body>

<div id="app">
    <cpn></cpn>
</div>

</body>

<template id="cpn">
    <div>
        <h1>我是cpn组件</h1>
        <ccpn></ccpn>
    </div>
</template>

<template id="ccpn">
    <div>
        <h1>子组件</h1>
        <button @click="btnClick">按钮</button>
    </div>
</template>

<script>
    const vue = new Vue({
        'el': '#app',
        'data': {
            msg: '我是父组件的属性'
        },
        'methods': {
            test() {
                console.log("我是父组件里面的方法")
            }
        },
        components: {
            cpn: {
                template: '#cpn',
                methods: {},
                data() {
                    return {
                        name: 'qxf'
                    }
                },
                components: {
                    ccpn: {
                        template: '#ccpn',
                        methods: {
                            btnClick() {
                                // 1,访问我们的父组件
                                // console.log(this.$parent);
                                // console.log(this.$parent.name);

                                // 2,访问根组件(也就是vue实例)
                                console.log(this.$root.msg);
                            }
                        }
                    }
                }
            }
        }
    })
</script>
</html>